package com.ys.peony.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.ys.peony.R;
import com.ys.peony.model.YWDJPrepareDanBaoItemModel;
import com.ys.peony.model.YWDJPrepareItemModel;

import java.util.List;

/**
 * 下拉框列表adapter
 */
public class ClientClassifyAdapter extends BaseAdapter{
    private List<YWDJPrepareDanBaoItemModel> data;
    private Context context;

    public ClientClassifyAdapter(Context context, List<YWDJPrepareDanBaoItemModel> data){
        super();
        this.data=data;
        this.context=context;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHold viewHold=null;
        if(convertView==null){
            convertView= LayoutInflater.from(context).inflate(R.layout.typeval_item_layout,null);
            viewHold=new ViewHold();
            viewHold.nametv=(TextView) convertView.findViewById(R.id.text_tv);
            convertView.setTag(viewHold);
        }else{
            viewHold=(ViewHold) convertView.getTag();
        }
        if(data.get(position)!=null){
            viewHold.nametv.setText(data.get(position).getName());
        }
        return convertView;
    }

    @Override
    public YWDJPrepareDanBaoItemModel getItem(int position) {
        return (data==null? null:data.get(position));
    }

    @Override
    public long getItemId(int position) {
        return (data==null? -1:position);
    }

    @Override
    public int getCount() {
        return (data==null? -1:data.size());
    }

    class ViewHold{
        private TextView nametv;
    }

    public void setData(List<YWDJPrepareDanBaoItemModel> data) {
        this.data = data;
        notifyDataSetChanged();
    }
}
